home *** CD-ROM | disk | FTP | other *** search
- Path: news.ios.com!usenet
- From: vlad@gramercy.ios.com (Vlastimil Adamovsky)
- Newsgroups: comp.lang.c++
- Subject: Re: Smart Pointer Implementation & question
- Date: Sat, 20 Jan 1996 00:46:26 GMT
- Organization: Internet Online Services
- Message-ID: <4dpdqe$1oc@news.ios.com>
- References: <4dfe36$d99@grid.direct.ca> <749@beech.ukc.ac.uk> <DLDw3H.7L1@research.att.com>
- NNTP-Posting-Host: ppp-41.ts-7.hck.idt.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- bs@research.att.com (Bjarne Stroustrup <9758-26353> 0112760) wrote:
-
-
- >Article 125614 of comp.lang.c++:
-
- >From: R.E.Jones@ukc.ac.uk (rej) writes
-
- > > In article <4dfe36$d99@grid.direct.ca>, Ken Clark <ken@direct.ca> wrote:
- > > >Hi. I have implemented a reference counting smart pointer class. It works
- > > >well, except that I can't get a basic behavior of normal pointers:
- > > >automatic casting of subclass pointers.
- > >
- > > This is a well-known problem with smart pointers.
- > >
- > > A good survey of the extent of the problem and possible solutions can be
- > > found in
- > >
- > > @inproceedings{edel92b,
- > > author = "Daniel R. Edelson",
- > > title = "Smart Pointers: They're Smart, But They're Not Pointers",
- > > booktitle = "USENIX C++ Conference",
- > > year = 1992
- > > }
-
- >However, things have progressed since that paper was written.
-
- >The problem is discussed in sec15.9.1 of D&E. You need member templates.
- >Here is the key example:
-
- >template<class T> class Ptr { // pointer to T
- > T* p;
- >public:
- > Ptr(T*);
- > template<class T2> operator Ptr<T2> () {
- > return Ptr<T2>(p); // works iff p can be
- > // converted to a T2*
- > }
- > // ...
- >};
-
- >That way, a Ptr<D> will convert to a Ptr<B> iff a D* converts to B*.
-
- > - Bjarne
-
- Which compiler does support the member templates?
-
-
- *******************************************
- * Vlastimil Adamovsky *
- * Smalltalk and C++ development *
- *******************************************
-
-